//
//  ImageCollectionViewCell.m
//  XRSquare
//
//  Created by 穆相臣 on 2018/8/24.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "ImageCollectionViewCell.h"

@interface ImageCollectionViewCell ()
{
    UIImageView * contentImage;
    UIButton * deleteButton;
}
@end

@implementation ImageCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        contentImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 90, 90)];
        contentImage.contentMode = UIViewContentModeScaleAspectFill;
        contentImage.clipsToBounds = YES;
        [self addSubview:contentImage];
        
        deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(90 - 40, 10, 30, 30)];
        [deleteButton setImage:[UIImage imageNamed:@"关闭2-fill"] forState:UIControlStateNormal];
        [deleteButton addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:deleteButton];
    }
    return self;
}

-(void)loadData:(NSString *)url
{
    if (url)
    {
        deleteButton.hidden = NO;
        [contentImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://pic.xrsquare.com/%@",url]]];
    }
    else
    {
        deleteButton.hidden = YES;
        contentImage.image = [UIImage imageNamed:@"发布"];
    }
}

-(void)deleteAction
{
    [self.delegate deleteImageIndex:self.currentIndex];
}

@end
